define(['jquery','bDialog/dialog'],function ($,dialog) {
    return {
        init:function(){

            //鼠标移动表格效果
            $("li[overstyle='on']").hover(
                function () {
                    $(this).addClass("bg_hover");
                },
                function () {
                    $(this).removeClass("bg_hover");
                }
            );
        },

        success:function(msg,times,fn){
            ZENG.msgbox.show(msg,4,times);
            if(fn){
                setTimeout(function() {
                    fn();
                }, times);
            }
        },
        error:function(msg,times,fn){
            ZENG.msgbox.show(msg,5,times);
            if(fn){
                setTimeout(function() {
                    fn();
                }, times);
            }
        },
        wait:function(msg){
            ZENG.msgbox.show(msg,6);
        },
        hide:function(){
            ZENG.msgbox.hide();
        },
        confirm:function(tip,fn){
            return dialog({id:'cdl',title:'温馨提示',content:tip,icon:'warning',ok:function(){
                if($.isFunction(fn)) fn();
                return false;
            },cancel:function(){ }});
        },arr2str:function(arr,sep){
            var temp=[];
            for(var i=0;i<arr.length;i++){
                if(arr[i]){
                    temp.push(arr[i]);
                }
            }
            return temp.join(sep);
        },

        /**
         * 收起与展开效果
         * @param integer cid 分类ID
         * @return boolean false
         */
        foldCategory:function(cid){
            var offImg = PUBLIC+'/Admin/images/off.png';
            var onImg = PUBLIC+'/Admin/images/on.png';
            $('#sub_'+cid).slideToggle('fast');
            $img = $('#img_'+cid);
            if($img.attr('src') == offImg) {
                $img.attr('src', onImg);
            } else {
                $img.attr('src', offImg);
            }
            return false;
        },
        /**
         * 移动分类位置
         * @param integer cid 分类ID
         * @param string type 移动类型
         * @param string stable 所操作的数据表
         * @return boolean false
         */
        moveTreeCategory : function(url,cid, type, stable) {
            var c=this;
            // 验证数据正确性
            if(typeof cid === "undefined" || typeof type === "undefined" || typeof stable === "undefined") {
                return false;
            }
            // 提交数据，修改排序位置
            $.post(url, {cid:cid, type:type, stable:stable}, function(msg) {
                if(msg.status == 1) {
                    c.success(msg.data);
                    location.href = location.href;
                } else {
                    c.error(msg.data,2000);
                }
                return false;
            }, 'json');
            return false;
        },
        /*
         * 状态
         * */
        setStatus:function(url){
            ZENG.msgbox.show('请等待...',6);
            $.ajax({
                type:"POST",
                url:"{:U('Admin/Seo/disables')}",
                dataType:"json",
                data:{
                    'id':id
                },
                success:function(data){
                    if (data.status==1){
                        ZENG.msgbox.show(data.info,4);
                        window.location.reload();
                    }else{
                        ZENG.msgbox.show(data.info,5,2000);
                    }
                }
            })
        },
        editer:function(obj){
            KindEditor.create('textarea[name="'+obj+'"]',{
                cssPath : PUBLIC+'/Common/KindEditor/plugins/code/prettify.css',
                uploadJson :FILEHOST,
                fileManagerJson : FILEHOST + 'file_manager_json.php',//20150104添加，文件管理空间
                filePostName : 'files[]',
                filterMode : false,
                allowFileManager : true,
                uploadFileJson : FILEHOST,
                extraFileUploadParams : {'do':'upload_editor_file','do_type':'ZG93bmxvYWQ=','operator':'manage'},//文件上传参数
                extraImageUploadParams : {'do':'upload_editor','do_type':'cHJvZHVjdA==','operator':'manage'},//图片上传参数

                afterCreate : function() {
                    this.sync();
                },
                afterBlur:function(){
                    this.sync();
                },
                resizeType:1
            });
        }

    };
});

//判断是否为空值 
function empty(v){
    switch (typeof v){
        case 'undefined' : return true;
        case 'string' : if(v.length == 0) return true; break;
        case 'boolean' : if(!v) return true; break;
        case 'number' : if(0 === v) return true; break;
        case 'object' :
            if(null === v) return true;
            if(undefined !== v.length && v.length==0) return true;
            for(var k in v){return false;} return true;
            break;
    }
    return false;
}

/* 根据表单ID 获取该表单所有值
 * 参数：frmID 表单ID名称
 */
function getForm(frmID){
    var frmID=document.getElementById(frmID);
    if(empty(frmID)) return;
    var i, fromdata={}, and = "";
    var item; // for each form's object
    var itemValue;// store each form object's value
    for( i=0;i<frmID.length;i++ ){
        item = frmID[i];// get form's each object
        if( item.name!='' ){
            if( item.type == 'select-one' ){
                itemValue = item.options[item.selectedIndex].value;
            }else if( item.type=='checkbox' || item.type=='radio') {
                if ( item.checked == false ) continue;
                itemValue = item.value;
            }else if( item.type == 'button' || item.type == 'submit' || item.type == 'reset' || item.type == 'image'){// ignore this type
                continue;
            }else{
                itemValue = item.value;
            }
            itemValue = encodeURIComponent(itemValue);
            fromdata[item.name]=itemValue;
        }
    }

    return fromdata;
}

//获取URL参数
function getParameter(val) {
    var uri = window.location.search;
    var re = new RegExp("" + val + "=([^&?]*)", "ig");
    return ((uri.match(re)) ? (uri.match(re)[0].substr(val.length + 1)) : '');
}

function filterHtml(html) {
	if(html=='' || html == undefined){
		return '';
	}else{
		var str = html.replace(/<[^>]+>/g, "");

    	return str;
	}
    
}

function filterSpecialCharacter(str){
    str = str.replace(/#/g, '%23');
    str = str.replace(/&/g, '%26');

    return str;
}

//获取字符串的长度
/**
 * 获取字符串的长度
 * @param str 字符串
 * @param mode 模式，若为空，则一个中文一个长度；否则一个中文占两个长度
 * @returns {*}
 */
function getLength(str,mode) {
    if(empty(str)){
        return 0;
    }else{
        if(empty(mode)){
            return str.length;
        }else{
            return Math.ceil(str.replace(/[^\x00-\xff]/g,"aa").length/2);
        }
        //return str.replace(/^\s+|\s+$/ig,'').replace(/[^\x00-\xff]/ig,'x').length;
    }
}
String.prototype.isEmpty = function(){if (this.replace(/(^\s*)|(\s*$)/g, "").length <= 0) { return true; } else { return false; }};
String.prototype.isEmail = function(){if(this.isEmpty() || (!/^([\w]+)(.[\w]+)*@([\w-]+\.){1,5}([A-Za-z]){2,4}$/.test(this))) { return false; } else { return true;}};
String.prototype.isMobile = function(){if(this.isEmpty() || (!/^(13[0-9]|145|147|15[0-9]|170|177|18[0-9])[0-9]{8}$/.test(this))) { return false; } else { return true; }};
String.prototype.isImg = function(){
    var strFilter = ".jpeg|.gif|.jpg|.png|.bmp|.pic";
    if(this.indexOf('.')>-1){
        var p = this.lastIndexOf(".");

        var strPostfix = this.substring(p,this.length) + '|';
        strPostfix = strPostfix.toLowerCase();

        if(strFilter.indexOf(strPostfix)>-1){
            return true;
        }
    }
    return false;
};

function HTMLDecode(text){
    var temp = document.createElement("div");
    temp.innerHTML = text;
    var output = temp.innerText || temp.textContent;
    if (output != '')
        output = unescape(output);
    temp = null;
    return output;
}

function urldecode(zipStr){
    var uzipStr="";
    for(var i=0;i<zipStr.length;i++){
        var chr = zipStr.charAt(i);
        if(chr == "+"){
            uzipStr+=" ";
        }else if(chr=="%"){
            var asc = zipStr.substring(i+1,i+3);
            if(parseInt("0x"+asc)>0x7f){
                uzipStr+=decodeURI("%"+asc.toString()+zipStr.substring(i+3,i+9).toString());
                i+=8;
            }else{
                uzipStr+=AsciiToString(parseInt("0x"+asc));
                i+=2;
            }
        }else{
            uzipStr+= chr;
        }
    }

    return uzipStr;
}

function StringToAscii(str){
    return str.charCodeAt(0).toString(16);
}
function AsciiToString(asccode){
    return String.fromCharCode(asccode);
}

//获取当前时间
function getCurTime(is_showtime){
	if(is_showtime==undefined) is_showtime = true;
	var myDate = new Date();
	var month = parseInt(myDate.getMonth())+1;
	var data = parseInt(myDate.getDate());
	var hour = parseInt(myDate.getHours());
	var minute = parseInt(myDate.getMinutes());
	if(month<10) month = '0'+ month;
	if(data<10) data = '0'+ data;
	if(hour<10) hour = '0'+ hour;
	if(minute<10) minute = '0'+ minute;
	
	if(!is_showtime)
		return myDate.getFullYear() + '-' + month + '-' + data;
	else
		return myDate.getFullYear() + '-' + month + '-' + data + ' ' + hour + ':' + minute;
}

function pageBack(){
    var a=window.location.href;
    if(/#top/.test(a)){
        window.history.go(-2);
        window.location.load(window.location.href)
    }else{
        window.history.back();
        window.location.load(window.location.href)
    }
}